//
//  Invoker.swift
//  命令设计模式
//
//  Created by slience on 2019/11/13.
//  Copyright © 2019 shehuiren. All rights reserved.
//

import UIKit

class Invoker: NSObject {
   
    
     var queue = NSMutableArray()
    
    static let shareInstance : Invoker = {
        
        let shareInstances = Invoker()
        
        return shareInstances
    }()
    
    public func addExecte(command : CommandProtocol){
        
        self.queue.add(command)
        command.execute()
    }
    
    public func rollBack(){
        
        if self.queue.count>0{
            
            let command : CommandProtocol = self.queue.lastObject as! CommandProtocol
            command.rollBackExecute()
            
            self.queue.removeLastObject()
        }
    }
    
    
}

public protocol CommandProtocol : NSObjectProtocol{
    
    func execute();
    
    func rollBackExecute();
}
